package com.czhong.rmi.client;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Enumeration;

/**
 * Created by DELL on 2017/2/18.
 */
public class UserClinet {
    public static void main(String[] as) throws NamingException, RemoteException, MalformedURLException, NotBoundException {
        Context nameContext = new InitialContext();

        System.out.println("RMI 绑定");
        Enumeration<NameClassPair> e = nameContext.list("rmi://localhost:8888/");
        while (e.hasMoreElements()){
            System.out.println(e.nextElement().getName());
        }
        System.out.println("RMI 连接");
        String url = "rmi://localhost:8888/bind_user";
        User user = (User) nameContext.lookup(url);
        //User user = (User) Naming.lookup(url);



        String name = "Zhong";

        int age = user.getAge(name);
        System.out.println("Name:"+name+"--Age"+age);
    }
}
